define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/service_records/index' + location.search,
                    //add_url: 'vppz/order/add',
                    edit_url: 'vppz/service_records/edit',
                    del_url: 'vppz/service_records/del',
                    multi_url: 'vppz/service_records/multi',
                    table: 'vppz_service_records',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
						{field: 'order_no', title: '订单号', operate: 'LIKE'},
						{field: 'user.avatar', title: '用户头像', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
						{field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
						{field: 'contect_name', title: '联系人', operate: 'LIKE'},
						{field: 'contect_phone', title: '联系电话', operate: 'LIKE'},
                        {field: 'patient_name', title: '病人姓名', operate: 'LIKE'},
                        {field: 'patient_sex', title: '病人性别'},
                        {field: 'patient_age', title: '病人年龄',searchable:false},

						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},

						{field: 'status', title: __('Status'), searchList: {"pending":__('Status pending'),"replied":__('Status replied')}, formatter: Table.api.formatter.status,custom:{'pending':'warning','replied':'success'}},//"0":__('Status 0'),



                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                    name: 'staff',
                                    title: '详情',
									text: '详情',
                                    width:'800px',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/service_records/detail'
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
